/**
* @program: src
*
* @description:
*
* @author: Mr.chen
*
* @create: 2020-12-18 17:03
**/
package handle

import (
	"ydd-im/service/api/define"
	"encoding/json"

)

/**
 *注册账号
 * @access  public
 * @param   string     username  账号
 * @param   string     passwd  密码
 * @param   string     userkey  用户id
 * @param   string     appkey  appkey
 * @return  mix
 */
func RegisterIsCluster(username,passwd,userkey,appkey string) (*define.ExecResult, error) {
	uInfo, _ := json.Marshal([]interface{}{username, passwd,userkey,appkey})
	res, err := execAction("/user/register", uInfo,define.ETCD_SERVER_Dbproxy_LIST,true)
	return parseBody(res), err
}
/**
 *登录
 * @access  public
 * @param   string     username  账号
 * @param   string     passwd  密码
 * @param   string     client  客户端
 * @param   string     appkey  appkey
 * @return  map[string]interface{} data 用户信息
 * @return  error err
 */
func LoginIsCluster(username,passwd,client,appkey string) (*define.ExecResult, error) {
	uInfo, _ := json.Marshal([]interface{}{username, passwd,client,appkey})
	res, err := execAction("/user/login", uInfo,define.ETCD_SERVER_Dbproxy_LIST,true)
	return parseBody(res), err
}
/**
 *登录
 * @access  public
 * @param   string     username  账号
 * @param   string     passwd  密码
 * @param   string     client  客户端
 * @param   string     appkey  appkey
 * @return  map[string]interface{} data 用户信息
 * @return  error err
 */
func GetUserInfoByTokenIsCluster(token string) (*define.ExecResult, error) {
	uInfo, _ := json.Marshal([]interface{}{token})
	res, err := execAction("/user/getUserInfoByToken", uInfo,define.ETCD_SERVER_Dbproxy_LIST,true)
	return parseBody(res), err
}
/**
 * 添加群，将指定的用户加入群
 * @access  public
 * @param   int     userid  用户id
 * @param   int     sid  群所属签名
 * @param   string     groupkey  群自定义id
 * @param   string     name  群名称
 * @param    []string     members  群成员
 * @return  mix
 */
func CreateGroupIsCluster(userid, sid int, groupkey, name string, members string) (*define.ExecResult, error) {
	uInfo, _ := json.Marshal([]interface{}{userid,sid,groupkey,name,members})
	res, err := execAction("/user/creategroup", uInfo,define.ETCD_SERVER_Dbproxy_LIST,true)
	return parseBody(res), err
}
/**
 * 加入群，将指定的用户加入群
 * @access  public
 * @param   int     userid  用户id
 * @param   int     sid  群所属签名
 * @param   string     groupkey  群自定义id
 * @param    []string     members  群成员
 * @return  mix
 */
func JoinGroupIsCluster(userid, sid int, groupkey string, members string) (*define.ExecResult, error) {
	uInfo, _ := json.Marshal([]interface{}{userid,sid,groupkey,members})
	res, err := execAction("/user/joingroup", uInfo,define.ETCD_SERVER_Dbproxy_LIST,true)
	return parseBody(res), err
}
